<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
html, body {
	width: 100%;
	padding: 0;
	margin: 0;
	text-align: center;
}

#addButton {
	font: Helvetica, sans-serif;
	font-size: 15px;
	margin-top: 50px;
	text-align: center;
}

button:hover {
	color: #7d7d7d;
	text-decoration: none;
}
</style>
<script type="text/javascript"
	src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
	function gotoPage(action) {
		var userName=$("#userName").val();
		var pageNum=0;
		//alert("userName="+userName);
		var currentPageNum = parseInt(document.getElementById("currentPageNum").value);
		var gotoPageNum = parseInt(document.getElementById("gotoPageNum").value);
		/* alert(gotoPageNum);
		alert(url); */
		//alert("currentPageNum="+currentPageNum);
		//设置查询页码
		//window.location.href = url + pageNum;
		if(action=="pre"){
			alert(124);
			pageNum=currentPageNum-1;
		}else if (action=="next") {
			pageNum=currentPageNum+1;
		}else{
			pageNum=gotoPageNum;
		}
		
		alert(pageNum);
		if(userName==null ||userName==""){
			
			window.location.href = 'http://localhost:8080/ssmdemo/user/userList.do?pageNum=' + pageNum;
		}else{
			$("#pageNum").val(pageNum);
			$("#form0").submit();
		}
		
	}
	
	function doSearch(){
         var userName = $("#userName2").val();
         $("#userName").val(userName);
         $("#form0").submit();
    };

</script>
<title>用户列表</title>
</head>
<body>
	<h2>用户列表</h2>
	<br>
	<br>
	<br>
	<br>
	<form id="form0"
		action="<%=request.getContextPath()%>/user/userList.do" method="post">
		姓名：<input type="text" id="userName2" name="userName2">
		<!-- <input type="button" id="search" value="查询"> -->
		<button id="searchBtn" value="查询" onclick="doSearch()">查询</button>
		<input type="hidden" id="pageNum" name="pageNum" value="${currentPageNum}"> <input
			type="hidden" id="userName" name="userName" value="${userName}">
		<input type="hidden" id="params" name="params">
	</form>
	<span id="msg" style="color: red;"></span>
	<table class="user_table" align="center" border="1px" width="500px">
		<thead>
			<tr>
				<td>用户ID</td>
				<td>姓名</td>
				<td>年龄</td>
				<td>操作</td>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${users}" var="user">
				<tr>
					<td>${user.id}</td>
					<td>${user.name}</td>
					<td>${user.age}</td>
					<td><a
						href="<%=request.getContextPath() %>/user/userAdd.do?userId=${user.id}">修改</a>
						<a
						href="<%=request.getContextPath() %>/user/userDelete.do?userId=${user.id}">删除</a></td>
				</tr>
			</c:forEach>
		</tbody>
	</table>
	<div class="pagenation">
		<c:if test="${currentPageNum != null && currentPageNum > 1}">
			<a href="JavaScript:void(0)"
				onclick="gotoPage('pre')">上一页</a>&nbsp;&nbsp;
		</c:if>
		<c:if test="${currentPageNum<totalPageNum}">
			<a href="JavaScript:void(0)"
				onclick="gotoPage('next')">下一页</a>&nbsp;&nbsp;
		</c:if>
		<input id="currentPageNum" type="hidden" name="currentPageNum"
			value="${currentPageNum}"> 共：<input type="text" size=5 id="totalPageNum"
			name="${currentPageNum}" readonly="readonly" value="${totalPageNum}">页&nbsp;&nbsp;
		跳转到：<input type="text" size=5 id="gotoPageNum" name="gotoPageNum"
			value="${currentPageNum}">页&nbsp;&nbsp;

		<button id="gotoButton" onclick="gotoPage('goto')">确定</button>
	</div>

	<button id="addButton"
		onclick="location='<%=request.getContextPath()%>/user/userAdd.do'">新增</button>
</body>
</html>